home *** CD-ROM | disk | FTP | other *** search
-
- if {[string compare test [info procs test]] == 1} then \
- {source defs}
-
- # set VERBOSE 1
- # set INTERACTIVE 1
-
- ############
- # work procs
- ############
-
- proc listItems {} {
- .listform.list getValues \
- -items i -itemCount n
- return "$n $i"
- }
-
- proc listSelectedItems {} {
- .listform.list getValues \
- -selectedItems i -selectedItemCount n
- return "$n $i"
- }
-
- proc indexToY {w n} {
- # calculate the Y co-ord for an index in the list
- $w getValues \
- -height h -itemCount count \
- -visibleItemCount vis
-
- set y [expr {(2*$n - 1) * $h / (2*$count)}]
- return $y
- }
-
- proc pause {} {
- # pause, so that repeated button clicks are not
- # mistaken for double clicks!
-
- # this stuff doesn't work like it should.
- # .listform.list getValues -doubleClickInterval c
- # set wait [expr {(2 * $c) / 1000}]
- # if {$wait < 1} {
- # set wait 1
- # }
- # exec sleep $wait
-
- # so busy wait instead
- set n 0
- while {$n < 10000} {incr n}
- }
-
- proc getIO {} {
- puts stdout "Press a key"
- gets stdin s
- }
-
- proc buttonPress {w n} {
- # simulate a button press
- return [$w callActionProc ListBeginSelect() \
- -type ButtonPress \
- -x 0 -y [indexToY $w $n]]
- }
-
- proc buttonRelease {w n} {
- # simulate a button release
- return [$w callActionProc ListEndSelect() \
- -type ButtonRelease \
- -x 0 -y [indexToY $w $n]]
- }
-
- #############
- # starts here
- #############
-
- xtAppInitialize -class List
- . setValues -allowShellResize true
-
- xmForm .listform managed
- xmList .listform.list managed \
- -visibleItemCount 4 \
- -items "a b c d" -itemCount 4
-
- . realizeWidget
-
- ######################
- # List element setting
- ######################
-
- test list-1.1 {list items} {
- listItems
- } {4 a b c d}
-
- test list-1.2 {resetting list items} {
- .listform.list setValues \
- -items "A B C D E" -itemCount 5
- listItems
- } {5 A B C D E}
-
- test list-1.3 {clearing list items} {
- .listform.list setValues \
- -items "" -itemCount 0
- listItems
- } {0 }
-
- test list-1.4 {resetting list items} {
- .listform.list setValues \
- -items "a b c d" -itemCount 4
- listItems
- } {4 a b c d}
-
- ################################
- # Selecting list items by code #
- ################################
-
- ########
- # select
- ########
- test list-2.1 {selecting list item} {
- .listform.list setValues \
- -selectedItems "b" -selectedItemCount 1
- listSelectedItems
- } {1 b}
-
- ##########
- # reselect
- ##########
- test list-2.2 {reselecting list items} {
- .listform.list setValues \
- -selectedItems "a c" -selectedItemCount 2
- listSelectedItems
- } {2 a c}
-
- #######
- # clear
- ######
- test list-2.3 {clearing list selection} {
- .listform.list setValues \
- -selectedItems "" -selectedItemCount 0
- listSelectedItems
- } {0 }
-
- ##########
- # reselect
- ##########
- test list-2.4 {reselecting list items} {
- .listform.list setValues \
- -selectedItems "a b c d" -selectedItemCount 4
- listSelectedItems
- } {4 a b c d}
-
- ###################################
- # Modifying list items by methods #
- ###################################
-
- ########
- # Adding
- ########
-
- test list-3.1 {adding list item at front} {
- .listform.list addItem aa 1
- listItems
- } {5 aa a b c d}
-
- test list-3.2 {adding list item at end} {
- .listform.list addItem e 0
- listItems
- } {6 aa a b c d e}
-
- test list-3.3 {adding list item in middle} {
- .listform.list addItem bb 4
- listItems
- } {7 aa a b bb c d e}
-
- ##########
- # Deleting
- ##########
-
- test list-3.4 {deleting list item at front} {
- .listform.list deleteItem aa
- listItems
- } {6 a b bb c d e}
-
- test list-3.5 {deleting list item at middle} {
- .listform.list deleteItem c
- listItems
- } {5 a b bb d e}
-
- if {$XmVersion >= 1002} {
- test list-3.6 {deleting all list items} {
- .listform.list deleteAllItems
- listItems
- } {0 }
- }
-
- test list-3.7 {adding item to empty list} {
- .listform.list setValues -items "" -itemCount 0
- .listform.list addItem a 1
- listItems
- } {1 a}
-
- test list-3.8 {deleting list item by position} {
- .listform.list deletePosition 1
- listItems
- } {0 }
-
-
- ####################
- # callback testing #
- ####################
-
- .listform.list setValues \
- -items "a b c d" -itemCount 4
- .listform.list singleSelectionCallback listSelectedItems
-
- test list-4.1 {single selection callback} {
- .listform.list setValues -selectionPolicy single_select \
- -selectedItems "" -selectedItemCount 0
- buttonPress .listform.list 1
- buttonRelease .listform.list 1
- } {1 a}
-
- test list-4.2 {single selection callback} {
- pause
- .listform.list setValues -selectionPolicy single_select \
- -selectedItems "" -selectedItemCount 0
- buttonPress .listform.list 2
- buttonRelease .listform.list 2
- listSelectedItems
- } {1 b}
-
- test list-4.3 {single selection callback} {
- pause
- .listform.list setValues -selectionPolicy single_select \
- -selectedItems "" -selectedItemCount 0
- buttonPress .listform.list 4
- buttonRelease .listform.list 4
- } {1 d}
-
- .listform.list destroyWidget
-
- ############################
- # % substitutions for list #
- ############################
-
- proc singleCB {item item_position} {
- return "$item $item_position"
- }
-
- proc multipleCB {selected_items} {
- return $selected_items
- }
-
- xmList .listform.list2 managed \
- -items "a b c d" -itemCount 4 \
- -visibleItemCount 4
-
- .listform.list2 singleSelectionCallback {singleCB %item %item_position}
- .listform.list2 multipleSelectionCallback {multipleCB {%selected_items}}
-
- ###############
- # Single select
- ###############
- test list-5.1 {% substitutions for single select} {
- .listform.list2 setValues \
- -selectionPolicy single_select \
- -selectedItems "" \
- -selectedItemCount 0
- buttonPress .listform.list2 2
- buttonRelease .listform.list2 2
- } {b 2}
-
- #################
- # Multiple select
- #################
- test list-5.2 {% substitutions for multiple select} {
- pause
- .listform.list2 setValues \
- -selectionPolicy multiple_select \
- -selectedItems "" \
- -selectedItemCount 0
- buttonPress .listform.list2 2
- buttonRelease .listform.list2 2
- pause
- buttonPress .listform.list2 3
- buttonRelease .listform.list2 3
- } {b c}
-
- .listform.list2 destroyWidget
-
- ###############################
- # Selection of items by methods
- ###############################
-
- xmList .listform.list3 managed
-
- .listform.list3 setValues \
- -items "a b c d" \
- -itemCount 4 \
- -selectedItems "" \
- -selectedItemCount 0 \
- -selectionPolicy single_select
-
- test list-6.1 {selectItem - single select} {
- .listform.list3 selectItem a false
- .listform.list3 selectItem c true
-
- listSelectedItems
- } {1 c}
-
- test list-6.2 {selectItem - multiple select} {
- .listform.list3 setValues \
- -items "a b c d" \
- -itemCount 4 \
- -selectedItems "" \
- -selectedItemCount 0 \
- -selectionPolicy multiple_select
-
- .listform.list3 selectItem c false
- .listform.list3 selectItem a false
-
- listSelectedItems
- } {2 a c}
-
- #################################
- # Deselection of items by methods
- #################################
-
- test list-7.1 {deselectItem - multiple select} {
- .listform.list3 setValues \
- -items "a b c d" \
- -itemCount 4 \
- -selectedItems "a b d" \
- -selectedItemCount 3 \
- -selectionPolicy multiple_select
-
- .listform.list3 deselectItem b
-
- listSelectedItems
- } {2 a d}
-
- test list-7.2 {deselectAllItems} {
- .listform.list3 deselectAllItems
-
- listSelectedItems
- } {0 }
-
- ################################
- # Selection of items by position
- ################################
-
- .listform.list3 deselectAllItems
- .listform.list3 setValues \
- -selectionPolicy multiple_select \
- -items "a b c d" \
- -itemCount 4 \
- -selectedItems "" \
- -selectedItemCount 0
-
- test list-8.1 {selectPosition} {
- .listform.list3 selectPosition 1 false
- .listform.list3 selectPosition 3 false
-
- listSelectedItems
- } {2 a c}
-
- test list-8.2 {deselectPosition} {
- .listform.list3 deselectPosition 1
-
- listSelectedItems
- } {1 c}
-
- if {$XmVersion >= 1002} {
- test list-8.3 {positionSelected - true} {
- .listform.list3 positionSelected 3
- } {true}
-
-
- test list-8.4 {positionSelected - false} {
- .listform.list3 positionSelected 2
- } {false}
- }
-
- ################
- # Item existence
- ################
-
- test list-9.1 {itemExists - true} {
- .listform.list3 itemExists c
- } {true}
-
- test list-9.2 {itemExists - false} {
- .listform.list3 itemExists ccccc
- } {false}
-
-
- #############
- # Finish up #
- #############
- if { ! $INTERACTIVE} {
- .listform.list destroyWidget
- .listform destroyWidget
- } else {
- . mainLoop
- }
-